
#include <stdio.h>
//#include <iostream>
#include <stdlib.h>
#include <sys/types.h>
#include <pthread.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>

void* producerThread(void* ptr);
void* consumerThread(void* ptr);

pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t mutex2 = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t mutex3 = PTHREAD_MUTEX_INITIALIZER;

char * produceList[] = {"test1","test2","test3"};
int pCtr=0;
int main(int argc, char* argv[])
{

     pthread_t thread1, thread2, thread3, thread4,thread5,thread6;
     char *message1 = "Thread 1";
     char *message2 = "Thread 2";
     int  iret1, iret2,iret3,iret4,iret5,iret6;
     //start top with fork and exec
     
    /* Create independent threads each of which will execute function */
    

     iret1 = pthread_create( &thread1, NULL, producerThread, (void*) message1);
     iret2 = pthread_create( &thread2, NULL, producerThread, (void*) message1);
     iret3 = pthread_create( &thread3, NULL, producerThread, (void*) message1);
     
     iret4 = pthread_create( &thread4, NULL, consumerThread, (void*) message1);
     iret5 = pthread_create( &thread5, NULL, consumerThread, (void*) message1);
     iret6 = pthread_create( &thread6, NULL, consumerThread, (void*) message1);          

     pthread_join( thread1, NULL);
     pthread_join( thread2, NULL);
     pthread_join( thread3, NULL);
     
     pthread_join( thread4, NULL);
     pthread_join( thread5, NULL);
     pthread_join( thread6, NULL);
    
     return 0;
     
}

void* producerThread(void* ptr)
{
     pid_t child_pid = fork();
     if(child_pid == 0) 
     {
       
       char *const paramList[] = {"producer","123456"};
       //child
       execv("producer", paramList);
       printf("Unknown command\n");
       exit(0);
     }
     else {
     }
}

void* consumerThread(void* ptr)
{
     pid_t child_pid = fork();
     if(child_pid == 0) 
     {

       char *const paramList[] = {"consumer"};
       //child
       execv("consumer", paramList);
       printf("Unknown command\n");
       exit(0);
     }
     else {
     
     }
}



